<?php

class Goods_name extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Goods_kind':
	 * @var integer $id
	 * @var string $name
	 * @var string $conditions_of_carriage
	 * @var integer $state
	 * @var string $create_time
	 */
	
	public $consignor_name;
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'goods_name';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('name','length','max'=>20),
			array('conditions_of_carriage','length','max'=>200),
			array('name,consignor_name,n_index', 'required'),
			array('n_index', 'numerical', 'integerOnly'=>true,'max'=>100),
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)//在验证之前将无需用户输入的字段写入
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
		}
		return true;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '索引号',
			'name' => '货物名称',
			'fk_consignor_id' =>'货主id',
			'consignor_name' =>'货主(发货人)',
			'n_index'=>'显示优先级', 
			'conditions_of_carriage' => '承运条件',
			'state' => '状态',
			'create_time' => '创建时间',
		);
	}
	
	public function safeAttributes(){
		$params=parent::safeAttributes();
		$params[]='consignor_name';
		return $params;
	}
}